/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.ddtroops.daoclasses;

import cz.muni.fi.pa165.ddtroops.daointerfaces.UserDAO;
import cz.muni.fi.pa165.ddtroops.entities.User;
import java.util.List;
import org.springframework.stereotype.Repository;

/**
 *
 * @author newohybat
 */
@Repository(value = "userDAO")
public class UserDAOImpl extends BaseDAOImpl<User> implements UserDAO  {

    @Override
    protected boolean isValid(User object) {
        return  object.getName()!=null &&
                object.getPassword()!=null &&
                object.getAuthority()!=null;
    }

    @Override
    protected boolean isIn(User object) {
        return getById(object.getId())!=null;
    }

    public User getByName(String name){
        if (name == null || name.equals("")) {
            throw new IllegalArgumentException("Parameter name is null or empty string");
        }
        User hero = (User) super.getEntityManager().createQuery("SELECT u FROM User u WHERE u.name = :name").setParameter("name", name).getSingleResult();

        return hero;
    }

}
